package com.leyou.auth.utils;

import com.leyou.auth.dto.UserDetail;

public class UserContext {

    private static final ThreadLocal<UserDetail> threadLocal = new ThreadLocal<>();

    /**
     * 向当前线程添加用户
     * @param detail
     */
    public static void setUser(UserDetail detail){
        threadLocal.set(detail);
    }

    /**
     * 从当前线程获取用户
     * @return
     */
    public static UserDetail getUser(){
        return threadLocal.get();
    }

    /**
     * 从当前线程移除用户
     */
    public static void removeUser(){
        threadLocal.remove();
    }
}
